#ifndef FND_CAR_H_
#define FND_CAR_H_
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include "ltbasedefs.h"
#include "car_road_info_manager.h"
#include <vector>


namespace GameLogic {
    class wheel ;
    class car : boost::noncopyable {
    public:
        virtual ~car(){}
        void update_pos_rotation() {
            do_update_pos_rotation() ;
        }
        LTVector position() const {return do_position() ;}
        LTRotation rotation() const {return do_rotation() ;}
        void update_action_logic() {do_update_action_logic() ;}
        int id()const {return m_id ;}
        void set_speed(float speed) {m_speed = speed ;}
        float speed() const {return m_speed ;}
        car(int id) ;
        void wheel_pos_rot(int ids, LTVector& pos, LTRotation& rot)
            {do_wheel_pos_rot(ids, pos, rot) ;}
        uint32 current_action() const {return m_currentAction;}
        void set_current_action(uint32 current_action) {m_currentAction = current_action;}
        float& steer_x_current() {return m_xCurrent;}
        float& steer_y_current() {return m_yCurrent;}
        float& y_steer() {return m_ySteer;}      // FIXME
        void update_car_steer(float timeInteval) {
            update_total_racing_time(timeInteval) ;
            do_update_car_steer(timeInteval) ;}
        void bind_roadpoints(boost::shared_ptr<car_road_info_manager> road) {
            m_roadpoints = road ;
            m_roadpoints->bind_car(id()) ;
        }
        float total_racing_time() const {return m_total_racing_time;}
        float total_runing_length() const {return m_total_run_length;}
        float average_speed() const {if(m_total_racing_time == 0.0) return 0.0 ;
            return m_total_run_length / m_total_racing_time ;}
        HOBJECT get_object() {return do_get_object() ;}
        wheel* get_wheel(int id) ;
        void add_a_wheel(HOBJECT wheel_obj) ;
        void update_wheels() ;
    protected:
        int m_id ;
        float m_speed ;
        float m_xCurrent ;
        float m_yCurrent ;
        uint32 m_currentAction ;
        float m_ySteer ;
        float m_total_racing_time ;
        boost::shared_ptr<car_road_info_manager> m_roadpoints;
        
        float m_total_run_length ;
        std::vector<boost::shared_ptr<wheel> > m_wheels ;
    private:
        void update_total_racing_time(float f) {
            m_total_run_length += f * m_speed ;
            m_total_racing_time += f ;}
        virtual void  do_update_pos_rotation() = 0 ;
        virtual void do_update_action_logic() = 0 ;
        virtual void do_update_car_steer(float timeInteval) = 0 ;
        virtual LTVector do_position() const = 0 ;
        virtual LTRotation do_rotation() const = 0 ;
        virtual HOBJECT do_get_object() = 0 ;
       
        virtual void do_wheel_pos_rot(int ids, LTVector& pos, LTRotation& rot) =0 ;
    } ;
}
        
#endif
